{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6c5710fe-86e8-4345-90ce-60a2602580b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': 'chatcmpl-8WaPUWGLpr243nq1V8xcPQGQT4LJD',\n",
       " 'object': 'chat.completion',\n",
       " 'created': 1702777148,\n",
       " 'model': 'gpt-3.5-turbo-0613',\n",
       " 'choices': [{'index': 0,\n",
       "   'message': {'role': 'assistant',\n",
       "    'content': None,\n",
       "    'function_call': {'name': 'get_connection',\n",
       "     'arguments': '{\\n  \"user_id1\": \"李华\",\\n  \"user_id2\": \"小王\"\\n}'}},\n",
       "   'logprobs': None,\n",
       "   'finish_reason': 'function_call'}],\n",
       " 'usage': {'prompt_tokens': 88,\n",
       "  'completion_tokens': 30,\n",
       "  'total_tokens': 118,\n",
       "  'pre_token_count': 4096,\n",
       "  'pre_total': 42,\n",
       "  'adjust_total': 41,\n",
       "  'final_total': 1},\n",
       " 'system_fingerprint': None}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "\n",
    "url = \"https://openai.api2d.net/v1/chat/completions\"\n",
    "\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',    \n",
    "    'Authorization': 'Bearer fk212271-dza4SUgOeIGfyMpwKi32tnP9tKPKWopL' \n",
    "}\n",
    "\n",
    "data = {\n",
    "  \"model\": \"gpt-3.5-turbo-0613\", \n",
    "  # \"model\": \"gpt-4-0613\",\n",
    "  \"messages\": [\n",
    "    {\"role\": \"user\", \"content\": \"李华和小王是不是认识？\"},\n",
    "  ],\n",
    "  \"functions\": [\n",
    "    {\n",
    "      \"name\": \"get_connection\",\n",
    "      \"description\": \"判断用户1和用户2 是否为朋友关系\",\n",
    "      \"parameters\": {\n",
    "        \"type\": \"object\",\n",
    "        \"properties\": {\n",
    "          \"user_id1\": {\n",
    "            \"type\": \"string\",\n",
    "            \"description\": \"用户ID 1\"\n",
    "          },\n",
    "          \"user_id2\": {\n",
    "            \"type\": \"string\",\n",
    "            \"description\": \"用户ID 2\"\n",
    "          },\n",
    "        },\n",
    "        \"required\": [\"user_id1\", \"user_id2\"]\n",
    "      }\n",
    "    }\n",
    "  ]\n",
    "}\n",
    "\n",
    "data = requests.post(url, headers=headers, json=data).json()\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "70cbc6cb-2f7b-479f-a0dc-310b957b79a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': 'chatcmpl-8WaSBi73oAS0uM2zENgfPVogowup6',\n",
       " 'object': 'chat.completion',\n",
       " 'created': 1702777315,\n",
       " 'model': 'gpt-4-0613',\n",
       " 'choices': [{'index': 0,\n",
       "   'message': {'role': 'assistant',\n",
       "    'content': '首先，启动你的 Ubuntu 系统，并打开终端。下面是安装 TensorFlow 的步骤：\\n\\n1. 首先更新你的系统：\\n```\\nsudo apt-get update\\nsudo apt-get upgrade\\n```\\n   \\n2. 然后，安装 python3 的 pip 程序，如果你还没安装 python3，也需要先安装 python3：\\n ```\\nsudo apt-get install python3-dev python3-pip\\n```\\n   \\n3. 安装 tensorflow 依赖项：\\n ```\\nsudo apt-get install -y build-essential gfortran libatlas-base-dev\\n```\\n   \\n4. 现在，你可以通过 pip 安装 tensorflow：\\n ```\\npip3 install tensorflow\\n```\\n   \\n请注意，这会安装最新版本的 TensorFlow。如果需要安装特定版本，可以注明版本号，比如：\\n ```\\npip3 install tensorflow==2.2.0\\n```\\n\\n\\n所以，转换成函数 `get_commneds` 形式：\\n\\n```python\\n{\\n  \"commands\": [\\n    \"sudo apt-get update\",\\n    \"sudo apt-get upgrade\",\\n    \"sudo apt-get install python3-dev python3-pip\",\\n    \"sudo apt-get install -y build-essential gfortran libatlas-base-dev\",\\n    \"pip3 install tensorflow\"\\n  ]\\n}\\n```'},\n",
       "   'logprobs': None,\n",
       "   'finish_reason': 'stop'}],\n",
       " 'usage': {'prompt_tokens': 91,\n",
       "  'completion_tokens': 297,\n",
       "  'total_tokens': 388,\n",
       "  'pre_token_count': 8192,\n",
       "  'pre_total': 2490,\n",
       "  'adjust_total': 2387,\n",
       "  'final_total': 103},\n",
       " 'system_fingerprint': None}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "  # \"model\": \"gpt-3.5-turbo-0613\", \n",
    "  \"model\": \"gpt-4-0613\",\n",
    "  \"messages\": [\n",
    "    {\"role\": \"user\", \"content\": \"如何在ubuntu上安装tensorflow？\"},\n",
    "  ],\n",
    "  \"functions\": [\n",
    "    {\n",
    "      \"name\": \"get_commends\",\n",
    "      \"description\": \"返回安装命令，用于在linux等系统中进行运行\",\n",
    "      \"parameters\": {\n",
    "        \"type\": \"object\",\n",
    "        \"properties\": {\n",
    "            \"commands\": {\n",
    "                \"type\": \"array\",\n",
    "                \"items\": {\n",
    "                    \"type\": \"string\",\n",
    "                    \"description\": \"shell命令\"\n",
    "                },\n",
    "                \"description\": \"包含多条shell命令，用于综合一起完成特定的任务\"\n",
    "            }\n",
    "        },\n",
    "        \"required\": [\"commands\"]\n",
    "      }\n",
    "    }\n",
    "  ]\n",
    "}\n",
    "\n",
    "data = requests.post(url, headers=headers, json=data).json()\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "bfedb578-6863-4525-859d-c5cd26ad899b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': 'chatcmpl-8WalWiJ8vpYwbMD8KEWjPA7ic2FJd',\n",
       " 'object': 'chat.completion',\n",
       " 'created': 1702778514,\n",
       " 'model': 'gpt-3.5-turbo-0613',\n",
       " 'choices': [{'index': 0,\n",
       "   'message': {'role': 'assistant',\n",
       "    'content': '要安装PaddlePaddle（飞桨），可以按照以下步骤进行操作：\\n\\n1. 确保您的机器已经安装了Python和pip。可以在终端中运行以下命令来检查它们的版本：\\n   ```\\n   python --version\\n   pip --version\\n   ```\\n\\n2. 在终端中运行以下命令来安装PaddlePaddle：\\n   ```\\n   pip install paddlepaddle\\n   ```\\n\\n   如果您希望安装GPU版本的PaddlePaddle（使用GPU加速），您还需要安装CUDA和cuDNN。您可以参考PaddlePaddle官方文档中的\"安装CUDA和cuDNN\"部分来完成这些步骤。\\n\\n3. 安装完成后，您可以在Python中导入PaddlePaddle并开始使用。以下是一个简单的示例代码：\\n   ```python\\n   import paddle\\n\\n   # 创建一个Tensor对象\\n   x = paddle.to_tensor([1, 2, 3, 4, 5])\\n\\n   # 执行一些操作\\n   y = paddle.mean(x)\\n   print(y.numpy())\\n   ```\\n\\n   运行上述代码，如果输出为3.0，则说明PaddlePaddle已经成功安装并可以正常使用。\\n\\n请注意，安装PaddlePaddle可能需要一些时间，具体取决于您的网络连接速度和计算机性能。'},\n",
       "   'logprobs': None,\n",
       "   'finish_reason': 'stop'}],\n",
       " 'usage': {'prompt_tokens': 67,\n",
       "  'completion_tokens': 340,\n",
       "  'total_tokens': 407,\n",
       "  'pre_token_count': 4096,\n",
       "  'pre_total': 42,\n",
       "  'adjust_total': 38,\n",
       "  'final_total': 4},\n",
       " 'system_fingerprint': None}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "  \"model\": \"gpt-3.5-turbo-0613\", \n",
    "  # \"model\": \"gpt-4-0613\",\n",
    "  \"messages\": [\n",
    "    {\"role\": \"user\", \"content\": \"如何安装paddle？\"},\n",
    "  ],\n",
    "  \"functions\": [\n",
    "    {\n",
    "            \"name\": \"get_commands\",\n",
    "            \"description\": \"Get a list of bash commands on an Ubuntu machine\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"commands\": {\n",
    "                        \"type\": \"array\",\n",
    "                        \"items\": {\n",
    "                            \"type\": \"string\",\n",
    "                            \"description\": \"A terminal command string\"\n",
    "                        },\n",
    "                        \"description\": \"List of terminal command strings to be executed\"\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"commands\"]\n",
    "            }\n",
    "        }\n",
    "  ]\n",
    "}\n",
    "\n",
    "data = requests.post(url, headers=headers, json=data).json()\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "ae73caee-0aa1-47c3-a7ae-7f926c230de7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import openai\n",
    "import json\n",
    "\n",
    "openai.api_base = 'https://openai.api2d.net/v1'\n",
    "openai.api_key = 'fk212271-dza4SUgOeIGfyMpwKi32tnP9tKPKWopL'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "804c45b1-e7a8-469f-b594-87f0c9724567",
   "metadata": {},
   "outputs": [],
   "source": [
    "completion = openai.ChatCompletion.create(\n",
    "    model=\"gpt-3.5-turbo-0613\",\n",
    "    messages=[{\"role\": \"user\", \"content\": \"What's the weather like in Boston?\"}],\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "40697771-d63f-41d5-b917-7894044a0c54",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<OpenAIObject chat.completion id=chatcmpl-8WaYW1kYnuGcBCtQmoghtU8frLzjX at 0x7fb52130c130> JSON: {\n",
       "  \"id\": \"chatcmpl-8WaYW1kYnuGcBCtQmoghtU8frLzjX\",\n",
       "  \"object\": \"chat.completion\",\n",
       "  \"created\": 1702777708,\n",
       "  \"model\": \"gpt-3.5-turbo-0613\",\n",
       "  \"choices\": [\n",
       "    {\n",
       "      \"index\": 0,\n",
       "      \"message\": {\n",
       "        \"role\": \"assistant\",\n",
       "        \"content\": \"I'm sorry, I cannot provide real-time weather updates as I am an AI language model and do not have access to current data. I recommend checking a reliable weather website or using a weather app for the most up-to-date information on the weather in Boston.\"\n",
       "      },\n",
       "      \"logprobs\": null,\n",
       "      \"finish_reason\": \"stop\"\n",
       "    }\n",
       "  ],\n",
       "  \"usage\": {\n",
       "    \"prompt_tokens\": 15,\n",
       "    \"completion_tokens\": 52,\n",
       "    \"total_tokens\": 67,\n",
       "    \"pre_token_count\": 4096,\n",
       "    \"pre_total\": 42,\n",
       "    \"adjust_total\": 41,\n",
       "    \"final_total\": 1\n",
       "  },\n",
       "  \"system_fingerprint\": null\n",
       "}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "completion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "f69d9467-504c-4712-b69f-61fc8f6d1f51",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<OpenAIObject chat.completion id=chatcmpl-8WaYqXQVMQgU5yiU97Olds5DjhoyJ at 0x7fb520e2fef0> JSON: {\n",
       "  \"id\": \"chatcmpl-8WaYqXQVMQgU5yiU97Olds5DjhoyJ\",\n",
       "  \"object\": \"chat.completion\",\n",
       "  \"created\": 1702777728,\n",
       "  \"model\": \"gpt-4-0613\",\n",
       "  \"choices\": [\n",
       "    {\n",
       "      \"index\": 0,\n",
       "      \"message\": {\n",
       "        \"role\": \"assistant\",\n",
       "        \"content\": null,\n",
       "        \"function_call\": {\n",
       "          \"name\": \"get_current_weather\",\n",
       "          \"arguments\": \"{\\n  \\\"location\\\": \\\"Boston\\\"\\n}\"\n",
       "        }\n",
       "      },\n",
       "      \"logprobs\": null,\n",
       "      \"finish_reason\": \"function_call\"\n",
       "    }\n",
       "  ],\n",
       "  \"usage\": {\n",
       "    \"prompt_tokens\": 82,\n",
       "    \"completion_tokens\": 16,\n",
       "    \"total_tokens\": 98,\n",
       "    \"pre_token_count\": 8192,\n",
       "    \"pre_total\": 2486,\n",
       "    \"adjust_total\": 2468,\n",
       "    \"final_total\": 18\n",
       "  },\n",
       "  \"system_fingerprint\": null\n",
       "}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "completion = openai.ChatCompletion.create(\n",
    "    model=\"gpt-4-0613\",\n",
    "    messages=[{\"role\": \"user\", \"content\": \"What's the weather like in Boston?\"}],\n",
    "    functions=[\n",
    "    {\n",
    "        \"name\": \"get_current_weather\",\n",
    "        \"description\": \"Get the current weather in a given location\",\n",
    "        \"parameters\": {\n",
    "            \"type\": \"object\",\n",
    "            \"properties\": {\n",
    "                \"location\": {\n",
    "                    \"type\": \"string\",\n",
    "                    \"description\": \"The city and state, e.g. San Francisco, CA\",\n",
    "                },\n",
    "                \"unit\": {\"type\": \"string\", \"enum\": [\"celsius\", \"fahrenheit\"]},\n",
    "            },\n",
    "            \"required\": [\"location\"],\n",
    "        },\n",
    "    }\n",
    "],\n",
    "function_call=\"auto\",\n",
    ")\n",
    "\n",
    "completion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "391cf704-773f-4336-8f38-532e98dc202d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<OpenAIObject chat.completion id=chatcmpl-8WaZ94MH0tmP2aQZBuTrGP6qZDY5C at 0x7fb52130c900> JSON: {\n",
       "  \"id\": \"chatcmpl-8WaZ94MH0tmP2aQZBuTrGP6qZDY5C\",\n",
       "  \"object\": \"chat.completion\",\n",
       "  \"created\": 1702777747,\n",
       "  \"model\": \"gpt-4-0613\",\n",
       "  \"choices\": [\n",
       "    {\n",
       "      \"index\": 0,\n",
       "      \"message\": {\n",
       "        \"role\": \"assistant\",\n",
       "        \"content\": \"To install TensorFlow for your GPU, you need to have some prerequisites installed:\\n\\n1. CUDA\\u00ae Toolkit \\u2014 TensorFlow supports CUDA 11.0\\n2. cuDNN SDK (v8.0.4 for CUDA 11.0)\\n3. GPU card with CUDA Compute Capability\\n4. One of the following Supported NVIDIA software for CUDA 11.0\\n\\nAfter installing the prerequisites, you can install TensorFlow GPU version by using pip. Here are the instructions:\\n\\nStep 1: Update and Upgrade your system:\\n```bash\\nsudo apt-get update\\nsudo apt-get upgrade\\n```\\n\\nStep 2: Verify You Have a CUDA-Capable GPU:\\n```bash\\nlspci | grep -i nvidia\\n```\\n\\nStep 3: Verify You Have a Supported Version of Linux:\\n```bash\\nuname -m && cat /etc/*release\\n```\\n\\nStep 4: Install Dependencies:\\n```bash\\nsudo apt-get install build-essential\\nsudo apt-get install cmake git unzip zip\\nsudo apt-get install python3-dev python3-pip python3-venv\\n```\\n\\nStep 5: Install CUDA toolkit and cuDNN:\\n\\nThe easiest way to install the CUDA toolkit and cuDNN is to run these commands:\\n```bash\\nwget https://developer.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run\\nsudo sh cuda_11.0.3_450.51.06_linux.run\\n```\\n\\nThen, to install cuDNN, you should:\\n\\n- Go to the [NVIDIA cuDNN page](https://developer.nvidia.com/rdp/cudnn-download), create an account, and download cuDNN 8.0.4 for CUDA 11.0.\\n\\n- Extract the cuDNN archive and move the contents to `/usr/local/cuda` :\\n```bash\\ntar -xzvf cudnn-11.0-linux-x64-v8.0.4.30.tgz\\nsudo cp cuda/include/cudnn*.h /usr/local/cuda/include\\nsudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64\\nsudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*\\n```\\n\\nStep 6: Install TensorFlow:\\n\\nNow, you can create your Python virtual environment and install TensorFlow:\\n```bash\\npython3 -m venv --system-site-packages ~/tensorflow_gpu\\nsource ~/tensorflow_gpu/bin/activate\\npip install --upgrade pip\\npip install \\\"tensorflow-gpu==2.4.1\\\"\\n```\\n\\nYou might need to change the TensorFlow version as per the latest version available.\\n\\nRemember, the commands might change slightly based on your OS version and the versions of the toolkits.\\n\\nAfter installing, you can test if the installation is successful using this python code:\\n```python\\nimport tensorflow as tf\\n\\nprint(\\\"Num GPUs Available: \\\", len(tf.config.experimental.list_physical_devices('GPU')))\\n```\\n\\nThis should return the number of GPUs available.\\n\\nLet me fetch the terminal commands for you to run:\\n\\n```jsx\\nfunctions.get_commands({\\n  commands: [\\\"sudo apt-get update\\\", \\\"sudo apt-get upgrade\\\", \\\"lspci | grep -i nvidia\\\", \\\"uname -m && cat /etc/*release\\\", \\\"sudo apt-get install build-essential cmake git unzip zip\\\", \\\"sudo apt-get install python3-dev python3-pip python3-venv\\\", \\n  \\\"wget https://developer.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run\\\", \\\"sudo sh cuda_11.0.3_450.51.06_linux.run\\\", \\\"tar -xzvf cudnn-11.0-linux-x64-v8.0.4.30.tgz\\\", \\n  \\\"sudo cp cuda/include/cudnn*.h /usr/local/cuda/include\\\", \\\"sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64\\\", \\\"sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*\\\", \\\"python3 -m venv --system-site-packages ~/tensorflow_gpu\\\", \\\"source ~/tensorflow_gpu/bin/activate\\\", \\\"pip install --upgrade pip\\\", \\\"pip install tensorflow-gpu==2.4.1\\\"]\\n})\\n```\\n\\nWhen you use bash commands, please verify and ensure that they are the correct versions and appropriate for your own system and its settings. Always cross-check against the official documentation for TensorFlow, Ubuntu, CUDA Toolkit and cuDNN, as versions might be updated in the official site time to time.\"\n",
       "      },\n",
       "      \"logprobs\": null,\n",
       "      \"finish_reason\": \"stop\"\n",
       "    }\n",
       "  ],\n",
       "  \"usage\": {\n",
       "    \"prompt_tokens\": 70,\n",
       "    \"completion_tokens\": 979,\n",
       "    \"total_tokens\": 1049,\n",
       "    \"pre_token_count\": 8192,\n",
       "    \"pre_total\": 2485,\n",
       "    \"adjust_total\": 2180,\n",
       "    \"final_total\": 305\n",
       "  },\n",
       "  \"system_fingerprint\": null\n",
       "}"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "example_user_input = \"How do I install Tensorflow for my GPU?\"\n",
    "\n",
    "completion = openai.ChatCompletion.create(\n",
    "    model=\"gpt-4-0613\",\n",
    "    messages=[{\"role\": \"user\", \"content\": example_user_input}],\n",
    "        functions=[\n",
    "        {\n",
    "            \"name\": \"get_commands\",\n",
    "            \"description\": \"Get a list of bash commands on an Ubuntu machine\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"commands\": {\n",
    "                        \"type\": \"array\",\n",
    "                        \"items\": {\n",
    "                            \"type\": \"string\",\n",
    "                            \"description\": \"A terminal command string\"\n",
    "                        },\n",
    "                        \"description\": \"List of terminal command strings to be executed\"\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"commands\"]\n",
    "            }\n",
    "        }\n",
    "        ],\n",
    "        function_call=\"auto\",\n",
    ")\n",
    "\n",
    "completion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "0da78819-f8d2-47d6-8e5f-16dae068ef49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<OpenAIObject at 0x7fb520db6810> JSON: {\n",
       "  \"role\": \"assistant\",\n",
       "  \"content\": null,\n",
       "  \"function_call\": {\n",
       "    \"name\": \"get_commands\",\n",
       "    \"arguments\": \"{\\n  \\\"commands\\\": [\\n    \\\"sudo apt-get update\\\",\\n    \\\"sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran\\\",\\n    \\\"sudo apt-get install python3-pip\\\",\\n    \\\"pip3 install -U pip testresources setuptools\\\",\\n    \\\"pip3 install -U numpy==1.19.5 keras_preprocessing==1.1.2 h5py==2.10.0 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11\\\",\\n    \\\"pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v44 'tensorflow<2'\\\"\\n  ]\\n}\"\n",
       "  }\n",
       "}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "example_user_input = \"How do I install Tensorflow for my GPU?\"\n",
    "\n",
    "completion = openai.ChatCompletion.create(\n",
    "    model=\"gpt-4-0613\",\n",
    "    messages=[{\"role\": \"user\", \"content\": example_user_input}],\n",
    "        functions=[\n",
    "        {\n",
    "            \"name\": \"get_commands\",\n",
    "            \"description\": \"Get a list of bash commands on an Ubuntu machine\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"commands\": {\n",
    "                        \"type\": \"array\",\n",
    "                        \"items\": {\n",
    "                            \"type\": \"string\",\n",
    "                            \"description\": \"A terminal command string\"\n",
    "                        },\n",
    "                        \"description\": \"List of terminal command strings to be executed\"\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"commands\"]\n",
    "            }\n",
    "        }\n",
    "        ],\n",
    "        function_call={\"name\": \"get_commands\"},\n",
    ")\n",
    "\n",
    "reply_content = completion.choices[0].message\n",
    "reply_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "ccf7902b-9a52-4d30-988a-1edc84d25b6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<OpenAIObject at 0x7fb520e27090> JSON: {\n",
       "  \"role\": \"assistant\",\n",
       "  \"content\": null,\n",
       "  \"function_call\": {\n",
       "    \"name\": \"get_commands\",\n",
       "    \"arguments\": \"{\\n  \\\"commands\\\": [\\n    \\\"sudo apt-get update\\\",\\n    \\\"sudo apt-get install nvidia-cuda-toolkit\\\",\\n    \\\"sudo apt-get install libcudnn8\\\",\\n    \\\"pip install torch torchvision\\\"\\n  ]\\n}\"\n",
       "  }\n",
       "}"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "example_user_input = \"in linux, to install cuda, cudnn and pytorch\"\n",
    "\n",
    "completion = openai.ChatCompletion.create(\n",
    "    model=\"gpt-3.5-turbo-0613\",\n",
    "    messages=[{\"role\": \"user\", \"content\": example_user_input}],\n",
    "        functions=[\n",
    "        {\n",
    "            \"name\": \"get_commands\",\n",
    "            \"description\": \"Get a list of bash commands on an Ubuntu machine\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"commands\": {\n",
    "                        \"type\": \"array\",\n",
    "                        \"items\": {\n",
    "                            \"type\": \"string\",\n",
    "                            \"description\": \"A terminal command string\"\n",
    "                        },\n",
    "                        \"description\": \"List of terminal command strings to be executed\"\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"commands\"]\n",
    "            }\n",
    "        }\n",
    "        ],\n",
    "        function_call={\"name\": \"get_commands\"},\n",
    ")\n",
    "\n",
    "reply_content = completion.choices[0].message\n",
    "reply_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "f4ef0ece-7277-4558-af95-7f4c98649615",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['sudo apt-get update',\n",
       " 'sudo apt-get install nvidia-cuda-toolkit',\n",
       " 'sudo apt-get install libcudnn8',\n",
       " 'pip install torch torchvision']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[\"sudo apt-get update\", \"sudo apt-get install nvidia-cuda-toolkit\", \"sudo apt-get install libcudnn8\", \"pip install torch torchvision\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a9f144ea-1d0b-4f92-b573-1852302cf1a4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3.10"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
